﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="guideLink.aspx.cs" Inherits="GDIT.page.manage.link.guideLink1" %>
<%@ Import namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="../../../css/m_guideLink.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div class="all">






<div class="guideLinksNav">
    <!--一级菜单开始-->
    <ul class="first">
        <asp:Repeater ID="MainNavRepeater" runat="server">
            <ItemTemplate>
                <li id='0_<%#DataBinder.Eval(Container.DataItem, "OID") %>'><a href="javascript:void(0);var href='<%#DataBinder.Eval(Container.DataItem, "LinkAddress") %>';" class="link"><%#DataBinder.Eval(Container.DataItem, "MenuName")%></a><a class="expand"></a></li>
            </ItemTemplate>
        </asp:Repeater>
    </ul>
    <!--一级菜单结束-->

    <!--二级菜单开始-->
    <ul class="second">
        <asp:Repeater ID="DetailNavRepeater" runat="server">
            <ItemTemplate>
                <li id='<%#DataBinder.Eval(Container.DataItem, "Main")%>_<%#DataBinder.Eval(Container.DataItem, "OID") %>'><a href="javascript:void(0);var href='<%#DataBinder.Eval(Container.DataItem, "LinkAddress") %>';" class="link"><%# DataBinder.Eval(Container.DataItem, "MenuName")%></a><a class="expand"></a></li>
            </ItemTemplate>
        </asp:Repeater>
    </ul>
    <!--二级菜单结束-->

    <!--三级菜单开始-->
    <ul class="third">
        <li id="aa_aaa"><a href="javascript:void(0);var href='http://www.baidu.com';" class="link">ffff</a></li>
        <li id="aa_bbb"><a href="javascript:void(0);var href='http://www.baidu.com';" class="link">eee</a></li>
    </ul>
    <!--三级菜单结束-->
</div>




<!--伸展按钮的点击处理开始-->
<script type="text/javascript">
    var expands = new Array(); //伸展图标
    var expandsIndex = 0;
    var lis = document.getElementsByTagName("li");//所有的li
    var alls = document.getElementsByTagName("*"); //所有标签
    var uls = document.getElementsByTagName("ul");//所有列表
    //获取标签
    for (var i = 0; i < alls.length; i++) {
        if (alls[i].className == "expand") {
            expands[expandsIndex] = alls[i];
            expandsIndex++;
        }
    }

    //li的原始显示
    for (var i = 0; i < lis.length; i++) {
        if (lis[i].parentNode.className != "first") {
            lis[i].style.display = "none";
        }
    }

    for (var i = 0; i < expands.length; i++) {
        expands[i].onclick = expand_onclick;//赋予事件
        expands[i].style.backgroundImage = "url(../../../img/manage/link/openGroup.gif)";
    }

    //伸展按钮的点击事件
    function expand_onclick() {
        var liId = this.parentNode.id; //父容器的id
        var liIds = new Array();
        liIds = liId.split("_");//分割后的两个id

        //获取下一级列表的集合
        var liNexts = new Array(); //下一级列表的集合
        var liNextsIndex = 0;
        for (var i = 0; i < lis.length; i++) {
            var lisIdTemps = lis[i].id.split("_");
            if (lisIdTemps[0] == liIds[1]) {
                liNexts[liNextsIndex] = lis[i];
                liNextsIndex++;
            }
        }
        
        ClearExpand(this.parentNode);
        if (this.style.backgroundImage.indexOf("open") > 0) {//展开列表
            ChangeOnlyImg(this);
            this.style.backgroundImage = "url(../../../img/manage/link/closeGroup.gif)";
            for (var i = 0; i < liNexts.length; i++) {
                var liIdTemp = liNexts[i].id;
                var liIdTemps = liIdTemp.split("_");
                if (liIdTemps[0] == liIds[1]) {
                    liNexts[i].style.display = "";
                } else {
                    liNexts[i].style.display = "none";
                }
            }
        } else if (this.style.backgroundImage.indexOf("close") > 0) {//收起列表
            this.style.backgroundImage = "url(../../../img/manage/link/openGroup.gif)";
        }
    }

    //收起所有下级列表
    function ClearExpand(li) {
        var bool = false; //标志是否循环到相应ul
        for (var i = 0; i < uls.length; i++) {
            if (bool == true) {
                var ulChilds = uls[i].getElementsByTagName("li");
                for (var j = 0; j < ulChilds.length; j++) {
                    ulChilds[j].style.display = "none"; //子li隐藏
                }
            }
            if (uls[i].className == li.parentNode.className) {
                bool = true;
            }
        }
    }

    //使同一列表中只有一个不同的按钮
    function ChangeOnlyImg(ev) {
        var ddddddddd = 0;
        for (var i = 0; i < expands.length; i++) {
            if (expands[i].parentNode.parentNode == ev.parentNode.parentNode) {
                expands[i].style.backgroundImage = "url(../../../img/manage/link/openGroup.gif)";
            }
        }
    }
</script>
<!--伸展按钮的点击处理结束-->




<!--弹出层开始-->
<div class="hyaline"></div>
<div class="popup">
    <asp:TextBox ID="txtId" runat="server" CssClass="id"></asp:TextBox>
    <a title="关闭" href="javascript:void(0);" class="close" onclick="ClosePopup();"></a>
    <span class="lblName">链接名字：</span>
    <asp:TextBox ID="txtName" runat="server" CssClass="name"></asp:TextBox>
    <span class="lblAddress">链接地址：</span>
    <asp:TextBox ID="txtLink" runat="server" CssClass="address" TextMode="MultiLine"></asp:TextBox>

    <asp:LinkButton ID="btnSave" runat="server" NavigateUrl="javascript:void(0);" CssClass="save" Title="保存" OnClick="btnSave_OnClick"></asp:LinkButton>
    <asp:LinkButton ID="btnAdd" runat="server" NavigateUrl="javascript:void(0);" CssClass="add" Title="添加" OnClick="btnAdd_OnClick"></asp:LinkButton>
    <asp:LinkButton ID="btnDelete" runat="server" NavigateUrl="javascript:void(0);" CssClass="delete" Title="删除" OnClick="btnDelete_OnClick"></asp:LinkButton>
</div>
<!--弹出层结束-->


<script type="text/javascript">
    function AddLinkOnclick() {
        var alls = document.getElementsByTagName("*");
        for (var i = 0; i < alls.length; i++) {
            if (alls[i].className == "link") {
                alls[i].onclick = link_onclick;
            } else if (alls[i].className == "popup") {
                popupNav = alls[i];
            }
        }
    }
    AddLinkOnclick(); //添加事件

    function link_onclick() {
        var self = this;
        var hyalineNav;//透明层
        var popupNav; //弹出层
        var idHidden; //隐藏的含id标签
        var txtName;//链接名称
        var txtAddress;//链接地址
        var alls = document.getElementsByTagName("*");
        for (var i = 0; i < alls.length; i++) {
            if (alls[i].className == "hyaline") {
                hyalineNav = alls[i];
            } else if (alls[i].className == "popup") {
                popupNav = alls[i];
            } else if (alls[i].className == "id") {
                idHidden = alls[i];
            } else if (alls[i].className == "name") {
                txtName = alls[i];
            } else if (alls[i].className == "address") {
                txtAddress = alls[i];
            }
        }
        hyalineNav.style.display = "block";
        popupNav.style.display = "block";
        idHidden.style.visibility = "";//先显示才能为其设值
        txtName.value = this.innerHTML;
        //alert(self.parentNode.id);
        //alert(DealId(self.parentNode.id, 1));
        //--------------------------------------------------
        idHidden.value= this.parentNode.id;//赋值ID
        txtAddress.value = DealHref(this.href, 1);
        document.body.focus(); //使链接失去焦点
        idHidden.style.visibility = "hidden";
    }

    function ClosePopup() {
        var hyalineNav; //透明层
        var popupNav; //弹出层
        var alls = document.getElementsByTagName("*");
        for (var i = 0; i < alls.length; i++) {
            if (alls[i].className == "hyaline") {
                hyalineNav = alls[i];
            } else if (alls[i].className == "popup") {
                popupNav = alls[i];
            }
        }
        hyalineNav.style.display = "none";
        popupNav.style.display = "none";
    }

    //处理id，返回id的相应部分
    function DealId(id, i) {
        var ids = new Array();
        ids = id.split("_");
        return ids[i];
    }

    //处理id，返回id的相应部分
    function DealHref(href, i) {
        var hrefs = new Array();
        hrefs = href.split("'");
        return hrefs[i];
    }

</script>


</div>
</form>
</body>
</html>
